<?

$db = new PDO("sqlite:../../delicious.db");

include('../../configuration.php');
include('../../querys.php');

$tag = $_GET['tag'];
if (isset($_GET['description']))
	$description = $_GET['description'];
else $description = NULL;
if (isset($_GET['xml']))
	$xml = $_GET['xml'];
else $xml = 0;

$tag = escape_string($tag);
$description = escape_string($description);

if ($DEBUG == 1) {
	echo "Tag: $tag <br>";
	echo "Desc: $description <br>";
}

$bool = $dupTag->execute(array($tag));
if ($bool != FALSE) {
	if(count($dupTag->fetchAll()) == 0) {
		$bool = $tagsInsert->execute(array(NULL, $tag, $description));
		if ($bool) {
			if ($xml == 0) 
				echo "JSON  ..";
			else {
				echo "XML ..";
			}
		}
		else {
			echo "An error occured when inserting the tag in the database. <br>";
		}
	}
	else {
		echo "Error, duplicate tag found. <br>";
	}
}
